// https://www.bilibili.com/video/BV1d54y1f7B3?spm_id_from=333.788.player.switch&vd_source=d6fe65f095f01f05591e89d810720ccc&p=33
// 2024-10-25

public class P037_打家劫舍1_递归法 {

    public static void main(String[] args) {
        System.out.println(fun(new int[] {2,7,9,3,1}));
    }

    private static int fun(int[] arr) {
        return fun(arr,arr.length-1);//传入数组的最大索引
    }

    private static int fun(int[] arr,int index) {
        if (index == 0 || index == 1) return arr[index];
        return Math.max(arr[index] + fun(arr,index-2),fun(arr,index-1));
    }

}
